package pl.edu.pw.polygen.db.entieties;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name="USERS")
public class User implements Serializable{
	
	private static final long serialVersionUID = 681123470250000789L;
	
	private Long id;
	private String login;
	private String passwd;
	private Date lastVisit;
	private List<Project> projects = new ArrayList<Project>();
	
	@Id
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "users_seq")
	@SequenceGenerator(name="users_seq", sequenceName = "users_seq")
	@Column(name="USER_ID")
	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}
	
	@Column(name="LOGIN", nullable=false)
	public String getLogin() {
		return login;
	}
	
	public void setLogin(String login) {
		this.login = login;
	}
	
	@Column(name="PASSWD", nullable=false)
	public String getPasswd() {
		return passwd;
	}
	
	public void setPasswd(String passwd) {
		this.passwd = passwd;
	}
	
	@Column(name="LAST_VISIT", nullable=false)
	public Date getLastVisit() {
		return lastVisit;
	}
	
	public void setLastVisit(Date lastVisit) {
		this.lastVisit = lastVisit;
	}

	@OneToMany(targetEntity=Project.class, mappedBy="user",cascade = CascadeType.ALL, fetch=FetchType.LAZY)
	public List<Project> getProjects() {
		return projects;
	}

	public void setProjects(List<Project> projects) {
		this.projects = projects;
	}
	
}
